package com.zhht.htzx.ui;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static com.nsgf.library.photopicker.PhotoPicker.EXTRA_VIEW_ID;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.RadioGroup;

import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.kunminx.architecture.ui.page.DataBindingConfig;
import com.kunminx.architecture.ui.state.State;
import com.kunminx.binding_state.BR;
import com.nsgf.library.data.api.AccountService;
import com.nsgf.library.data.bean.BusinessBean;
import com.nsgf.library.data.bean.BusinessSettleTypeBean;
import com.nsgf.library.data.bean.LibraryInfo;
import com.nsgf.library.data.bean.WorkOrderDetailBean;
import com.nsgf.library.data.repository.DataRepository;
import com.nsgf.library.data.response.ResponseStatus;
import com.nsgf.library.domain.request.AccountRequester;
import com.nsgf.library.domain.request.BaseHttpObserver;
import com.nsgf.library.domain.request.HttpOnNextListener;
import com.nsgf.library.matisse.Matisse;
import com.nsgf.library.matisse.MimeType;
import com.nsgf.library.photopicker.PhotoPicker;
import com.nsgf.library.photopicker.widget.MultiPickResultView;
import com.nsgf.library.photopicker.widget.PhotoAdapter;
import com.nsgf.library.ui.page.BaseActivity;
import com.nsgf.library.ui.page.StateHolder;
import com.nsgf.library.ui.page.WebViewApiActivity;
import com.nsgf.library.utils.StringUtil;
import com.nsgf.library.utils.ToastUtils;
import com.nsgf.library.widget.prckerview.OptionsPickerView;
import com.nsgf.library.widget.prckerview.TimePickerView;
import com.zhht.htzx.R;
import com.zhht.htzx.databinding.ActivityBusinessNewSettleBinding;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * 商家入驻
 */
public class BusinessNewSettledActivity extends BaseActivity {

    private BusinessSettleStateHolder mStates;
    private AccountRequester mAccountRequester;

    @Override
    protected void initViewModel() {
        mStates = getActivityScopeViewModel(BusinessSettleStateHolder.class);
        mAccountRequester = getActivityScopeViewModel(AccountRequester.class);
    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        return new DataBindingConfig(R.layout.activity_business_new_settle, BR.vm, mStates)
                .addBindingParam(BR.click, new ClickProxy());
    }

    private ActivityBusinessNewSettleBinding mBinding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mStates.titleBar.set("商家入驻");
        getLifecycle().addObserver(mAccountRequester);
        mBinding = (ActivityBusinessNewSettleBinding) getBinding();
        mBinding.titlebar.titleBarRoot.setTextColor(getResources().getColor(R.color.white));
        mBinding.titlebar.titleBarBack.setImageResource(R.drawable.ic_titlebar_white_back);
        mAccountRequester.getShopTypes();
        mAccountRequester.getLibraryList().observe(this, new Observer<ResponseStatus<List<LibraryInfo>>>() {
            @Override
            public void onChanged(ResponseStatus<List<LibraryInfo>> listResponseStatus) {
                if (listResponseStatus.getResponseCode() == 0) {
                    mStates.shopTypes.set(listResponseStatus.getData());
                }
            }
        });
        mAccountRequester.queryServiceCenters();
        mAccountRequester.getBusinessResult().observe(this, new Observer<ResponseStatus<List<BusinessBean>>>() {
            @Override
            public void onChanged(ResponseStatus<List<BusinessBean>> listResponseStatus) {
                if (listResponseStatus.getResponseCode() == 0) {
                    mStates.serviceTypes.set(listResponseStatus.getData());
                }
            }
        });

        mBinding.mprvBusinessLicense.init(this,
                MultiPickResultView.ACTION_SELECT,
                new ArrayList<>(),
                1,
                0,
                MimeType.ofAll(), new PhotoAdapter.PhotoOnClick() {
                    @Override
                    public void setPhotoListener(int position) {
                    }
                });

        mBinding.mprvIdentificationCertBackPhoto.init(this,
                MultiPickResultView.ACTION_SELECT,
                new ArrayList<>(),
                1,
                1,
                MimeType.ofAll(), new PhotoAdapter.PhotoOnClick() {
                    @Override
                    public void setPhotoListener(int position) {
                    }
                });

        mBinding.mprvIdentificationFrontPhoto.init(this,
                MultiPickResultView.ACTION_SELECT,
                new ArrayList<>(),
                1,
                2,
                MimeType.ofAll(), new PhotoAdapter.PhotoOnClick() {
                    @Override
                    public void setPhotoListener(int position) {
                    }
                });

        mBinding.mprvAccountOpeningPermit.init(this,
                MultiPickResultView.ACTION_SELECT,
                new ArrayList<>(),
                1,
                3,
                MimeType.ofAll(), new PhotoAdapter.PhotoOnClick() {
                    @Override
                    public void setPhotoListener(int position) {
                    }
                });

        mBinding.mprvBank.init(this,
                MultiPickResultView.ACTION_SELECT,
                new ArrayList<>(),
                1,
                4,
                MimeType.ofAll(), new PhotoAdapter.PhotoOnClick() {
                    @Override
                    public void setPhotoListener(int position) {
                    }
                });

        mBinding.mprvBusinessHeadPhoto.init(this,
                MultiPickResultView.ACTION_SELECT,
                new ArrayList<>(),
                1,
                5,
                MimeType.ofAll(), new PhotoAdapter.PhotoOnClick() {
                    @Override
                    public void setPhotoListener(int position) {
                    }
                });

        mBinding.mprvBusinessJobPhoto.init(this,
                MultiPickResultView.ACTION_SELECT,
                new ArrayList<>(),
                1,
                6,
                MimeType.ofAll(), new PhotoAdapter.PhotoOnClick() {
                    @Override
                    public void setPhotoListener(int position) {
                    }
                });

        mBinding.mprvBusinessReceptionPhoto.init(this,
                MultiPickResultView.ACTION_SELECT,
                new ArrayList<>(),
                1,
                7,
                MimeType.ofAll(), new PhotoAdapter.PhotoOnClick() {
                    @Override
                    public void setPhotoListener(int position) {
                    }
                });

        mAccountRequester.getSrcSuccess().observe(this, new Observer<ResponseStatus<String>>() {
            @Override
            public void onChanged(ResponseStatus<String> stringResponseStatus) {
                getController().dismissLoading();
                if (stringResponseStatus.getResponseCode() == 0) {
                    ToastUtils.showShortToast(stringResponseStatus.getMsg());
//                    finish();
                }
            }
        });
        mAccountRequester.getTenantTypes();
        mAccountRequester.getBusinessSettleTypeResult().observe(this, new Observer<ResponseStatus<List<BusinessSettleTypeBean>>>() {
            @Override
            public void onChanged(ResponseStatus<List<BusinessSettleTypeBean>> listResponseStatus) {
                if (listResponseStatus.getResponseCode() == 0) {
                    mBinding.radioTagGroup.setTags(listResponseStatus.getData());
                    // 设置选择监听器
                    mBinding.radioTagGroup.setOnTagSelectedListener((position, tag) -> {
                        if (position == 1) {
                            mBinding.llBusinessType.setVisibility(VISIBLE);
                        } else {
                            mBinding.llBusinessType.setVisibility(GONE);
                        }
                        mStates.zhhtMerchantsType.set(listResponseStatus.getData().get(position).getTypeId());
                    });
                }
            }
        });

        mBinding.radioTagGroupBusinessType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {

                if (radioGroup.getCheckedRadioButtonId() == mBinding.radioButtonBusinessTypeGt.getId()) {
                    mBinding.llBusinessRegCapital.setVisibility(GONE);
                    mStates.entType.set("5");
                } else {
                    mBinding.llBusinessRegCapital.setVisibility(VISIBLE);
                    mStates.entType.set("3");
                }

            }
        });


        mBinding.rgBusinessLicenseType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {

                if (radioGroup.getCheckedRadioButtonId() == mBinding.rgBusinessLicenseYj.getId()) {
                    mBinding.llLicenseEndTime.setVisibility(GONE);
                    mStates.licenseValidityType.set("1");
                } else {
                    mBinding.llLicenseEndTime.setVisibility(VISIBLE);
                    mStates.licenseValidityType.set("0");
                }

            }
        });


        mBinding.rgFrType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {

                if (radioGroup.getCheckedRadioButtonId() == mBinding.rbFrYj.getId()) {
                    mBinding.llBusinessFrEndTime.setVisibility(GONE);
                    mStates.legalCertValidityType.set("1");
                } else {
                    mStates.legalCertValidityType.set("0");
                    mBinding.llBusinessFrEndTime.setVisibility(VISIBLE);
                }

            }
        });

        mBinding.rgBusinessBankType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {

                if (radioGroup.getCheckedRadioButtonId() == mBinding.rbBusinessDg.getId()) {
                    mStates.cardType.set("0");
                    mBinding.llBusinessBankDg.setVisibility(VISIBLE);
                    mBinding.llBusinessBankDs.setVisibility(GONE);
                } else {
                    mStates.cardType.set("1");
                    mBinding.llBusinessBankDg.setVisibility(GONE);
                    mBinding.llBusinessBankDs.setVisibility(VISIBLE);
                }

            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (RESULT_OK == resultCode) {
            if (PhotoPicker.REQUEST_CODE == requestCode) {
                getController().displayLoading();
                int index = data.getIntExtra(EXTRA_VIEW_ID, 0);

                ArrayList<WorkOrderDetailBean.FileDto> photos = new ArrayList<>();
                for (String src : Matisse.obtainPathResult(data)) {
                    WorkOrderDetailBean.FileDto dto = new WorkOrderDetailBean.FileDto();
                    dto.setFilePath(src);
                    photos.add(dto);
                }

                switch (index) {
                    case 0:
                        mBinding.mprvBusinessLicense.photoAdapter.refresh(photos);
                        break;
                    case 1:
                        mBinding.mprvIdentificationCertBackPhoto.photoAdapter.refresh(photos);

                        break;
                    case 2:
                        mBinding.mprvIdentificationFrontPhoto.photoAdapter.refresh(photos);

                        break;
                    case 3:
                        mBinding.mprvAccountOpeningPermit.photoAdapter.refresh(photos);
                        break;
                    case 4:
                        mBinding.mprvBank.photoAdapter.refresh(photos);
                        break;
                    case 5:
                        mBinding.mprvBusinessHeadPhoto.photoAdapter.refresh(photos);
                        break;
                    case 6:
                        mBinding.mprvBusinessJobPhoto.photoAdapter.refresh(photos);
                        break;
                    case 7:
                        mBinding.mprvBusinessReceptionPhoto.photoAdapter.refresh(photos);
                        break;


                }
                List<String> arrayList = new ArrayList<>();

                for (WorkOrderDetailBean.FileDto fileDto : photos) {
//                    mAccountRequester.uploadFile(fileDto.getFilePath());

                    File file = new File(fileDto.getFilePath());
                    RequestBody requestBody = RequestBody.create(file, MediaType.parse("multipart/form-data"));
                    MultipartBody.Part filePart = MultipartBody.Part.createFormData("file", file.getName(), requestBody);

                    Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                            .uploadFile(filePart);
                    BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<Object>>
                            (new HttpOnNextListener<ResponseStatus<Object>>() {
                                @Override
                                public void onSuccess(ResponseStatus<Object> dataResult) {

                                    if (dataResult.getResponseCode() == 0) {
                                        arrayList.add(dataResult.getData().toString());
                                        fileDto.setHttpPath(dataResult.getData().toString());
                                        if (photos.size() == arrayList.size()) {
                                            getController().dismissLoading();

                                            if (index == 0) {
                                                mStates.licensePic.set(dataResult.getData().toString());
                                            } else if (index == 1) {
                                                mStates.legalCertBackPic.set(dataResult.getData().toString());
                                            } else if (index == 2) {
                                                mStates.legalCertFrontPic.set(dataResult.getData().toString());
                                            } else if (index == 3) {
                                                mStates.regAcctPic.set(dataResult.getData().toString());
                                            } else if (index == 4) {
                                                mStates.settleCardFrontPic.set(dataResult.getData().toString());
                                            } else if (index == 5) {
                                                mStates.storeHeaderPic.set(dataResult.getData().toString());
                                            } else if (index == 6) {
                                                mStates.storeIndoorPic.set(dataResult.getData().toString());
                                            } else if (index == 7) {
                                                mStates.storeCashierDeskPic.set(dataResult.getData().toString());
                                            }
                                        }
                                    }
                                }

                                @Override
                                public void onFail(String e) {


                                }

                                @Override
                                public void onComplete() {
                                }
                            });
                    DataRepository.getInstance().subscribe(observable, observer);

                }
            } else if (1006 == requestCode) {
                LibraryInfo info = (LibraryInfo) data.getSerializableExtra("data");
                mStates.mcc.set(info.getName());
                mStates.mccCode.set(info.getCode());
            }

        }

    }


    public static class BusinessSettleStateHolder extends StateHolder {
//        public final State<String> regName = new State<>("众合惠通(海南)投资有限公司");
//        public final State<String> shortName = new State<>("众合惠通(海南)投资有限公司");
//        public final State<String> entType = new State<>("5");//公司类型，3：私营企业 5：个体工商户
//        public final State<String> regCapital = new State<>("1000000");//注册资本
//        public final State<String> regDistrictId = new State<>("460100");//注册区，参考地区码；
//
//
//        public final State<String> licensePic = new State<>("");//营业执照图片地址
//        public final State<String> licenseCode = new State<>("91460100MAD1KIPC5L");
//        public final State<String> licenseValidityType = new State<>("0");//营业执照是否长期
//        public final State<String> licenseBeginDate = new State<>("2023-11-06");
//        public final State<String> licenseEndDate = new State<>("2025-10-10");
//        public final State<String> legalCertType = new State<>("00");
//
//        public final State<String> foundDate = new State<>("2023-11-06");
//        public final State<String> regDetail = new State<>("海南省海口市江东新区海涛大道1001号海口经济学院创新创业大厦3楼3D002");
//        public final State<String> legalName = new State<>("王龙");
//        public final State<String> legalCertNo = new State<>("320324198411191912");
//        public final State<String> legalCertValidityType = new State<>("0");
//        public final State<String> legalCertBeginDate = new State<>("2012-06-27");
//        public final State<String> legalCertEndDate = new State<>("2032-06-27");
//        public final State<String> legalAddr = new State<>("江苏省睢宁县姚集镇娄埝村娄场一组17号");
//        public final State<String> legalCertBackPic = new State<>("");//法人身份证国徽面，通过图片上传接口上传材料；文件类型：F03
//
//
//        public final State<String> legalCertFrontPic = new State<>("");//法人身份证人像面，通过图片上传接口上传材料；文件类型：F02
//
//
//        public final State<String> contactName = new State<>("");
//        public final State<String> contactEmail = new State<>("1252356679@qq.com");
//        public final State<String> contactMobileNo = new State<>("13151095413");
//        public final State<String> regAcctPic = new State<>("");//开户许可证
//        public final State<String> openLicenceNo = new State<>("J3010078192102");
//        public final State<String> cardType = new State<>("1");//0：对公账户 1：对私法人账户 2：对私非法人账户
//        public final State<String> cardName = new State<>("王龙");
//        public final State<String> cardNo = new State<>("6217001310001376041");
//        public final State<String> mcc = new State<>("");
//        public final State<String> mccCode = new State<>("");
//        public final State<String> bankAreaId = new State<>("321200");//银行所在市，参考地区编码；如修改省市要级联修改areaId
//
//
//        public final State<String> bankName = new State<>("建设银行");
//        public final State<String> settleCardFrontPic = new State<>("");
//        public final State<String> subBankName = new State<>("中国建设银行股份有限公司泰州分行");
//        public final State<String> storeHeaderPic = new State<>("");//店铺门头照，通过图片上传接口上传材料；文件类型：F22；微信/支付宝实名认证个人商户，门头照也使用此字段；门店场所：提交门店门口照片，要求招牌标识可见；小微商户流动经营/便民服务：提交经营/服务现场照片
//        public final State<String> storeIndoorPic = new State<>("");//店铺内景/工作区域照，通过图片上传接口上传材料；文件类型：F24；微信/支付宝实名认证个人商户，内景照也使用此字段；门店场所：提交店内环境照片；小微商户流动经营/便民服务：可提交另一张经营/服务现场照片
//        public final State<String> storeCashierDeskPic = new State<>("");//店铺收银台/公司前台照，通过图片上传接口上传材料；文件类型：F105；微信/支付宝实名认证个人商户，内景照也使用此字段；门店场所：提交收银台/公司前台照片；小微商户流动经营/便民服务：可提交另一张经营/服务现场照片
//
//        public final State<String> spid = new State<>("13541");
//        public final State<String> typeId = new State<>("");
//        public final State<String> typeName = new State<>("");
//        public final State<String> zhhtMerchantsType = new State<>("");
//        public final State<String> serviceCenterId = new State<>("");
//        public final State<String> serviceCenterName = new State<>("");
//
//        public final State<Boolean> checked = new State<>(false);
//        public final State<List<LibraryInfo>> shopTypes = new State<>(new ArrayList<>());
//        public final State<List<BusinessBean>> serviceTypes = new State<>(new ArrayList<>());


        public final State<String> regName = new State<>("");
        public final State<String> shortName = new State<>("");
        public final State<String> entType = new State<>("5");//公司类型，3：私营企业 5：个体工商户
        public final State<String> regCapital = new State<>("");//注册资本
        public final State<String> regDistrictId = new State<>("");//注册区，参考地区码；


        public final State<String> licensePic = new State<>("");//营业执照图片地址
        public final State<String> licenseCode = new State<>("");
        public final State<String> licenseValidityType = new State<>("0");//营业执照是否长期
        public final State<String> licenseBeginDate = new State<>("");
        public final State<String> licenseEndDate = new State<>("");
        public final State<String> legalCertType = new State<>("00");

        public final State<String> foundDate = new State<>("");
        public final State<String> regDetail = new State<>("");
        public final State<String> legalName = new State<>("");
        public final State<String> legalCertNo = new State<>("");
        public final State<String> legalCertValidityType = new State<>("0");
        public final State<String> legalCertBeginDate = new State<>("");
        public final State<String> legalCertEndDate = new State<>("");
        public final State<String> legalAddr = new State<>("");
        public final State<String> legalCertBackPic = new State<>("");//法人身份证国徽面，通过图片上传接口上传材料；文件类型：F03


        public final State<String> legalCertFrontPic = new State<>("");//法人身份证人像面，通过图片上传接口上传材料；文件类型：F02


        public final State<String> contactName = new State<>("");
        public final State<String> contactEmail = new State<>("");
        public final State<String> contactMobileNo = new State<>("");
        public final State<String> regAcctPic = new State<>("");//开户许可证
        public final State<String> openLicenceNo = new State<>("");
        public final State<String> cardType = new State<>("1");//0：对公账户 1：对私法人账户 2：对私非法人账户
        public final State<String> cardName = new State<>("");
        public final State<String> cardNo = new State<>("");
        public final State<String> mcc = new State<>("");
        public final State<String> mccCode = new State<>("");
        public final State<String> bankAreaId = new State<>("");//银行所在市，参考地区编码；如修改省市要级联修改areaId


        public final State<String> bankName = new State<>("");
        public final State<String> settleCardFrontPic = new State<>("");
        public final State<String> subBankName = new State<>("");
        public final State<String> storeHeaderPic = new State<>("");//店铺门头照，通过图片上传接口上传材料；文件类型：F22；微信/支付宝实名认证个人商户，门头照也使用此字段；门店场所：提交门店门口照片，要求招牌标识可见；小微商户流动经营/便民服务：提交经营/服务现场照片
        public final State<String> storeIndoorPic = new State<>("");//店铺内景/工作区域照，通过图片上传接口上传材料；文件类型：F24；微信/支付宝实名认证个人商户，内景照也使用此字段；门店场所：提交店内环境照片；小微商户流动经营/便民服务：可提交另一张经营/服务现场照片
        public final State<String> storeCashierDeskPic = new State<>("");//店铺收银台/公司前台照，通过图片上传接口上传材料；文件类型：F105；微信/支付宝实名认证个人商户，内景照也使用此字段；门店场所：提交收银台/公司前台照片；小微商户流动经营/便民服务：可提交另一张经营/服务现场照片

        public final State<String> spid = new State<>("");
        public final State<String> typeId = new State<>("");
        public final State<String> typeName = new State<>("");
        public final State<String> zhhtMerchantsType = new State<>("");
        public final State<String> serviceCenterId = new State<>("");
        public final State<String> serviceCenterName = new State<>("");

        public final State<Boolean> checked = new State<>(false);
        public final State<List<LibraryInfo>> shopTypes = new State<>(new ArrayList<>());
        public final State<List<BusinessBean>> serviceTypes = new State<>(new ArrayList<>());



    }

    private JsonObject getHttpParams() {
        JsonObject params = new JsonObject();

        params.addProperty("licenseCode", mStates.licenseCode.get());
        params.addProperty("licenseBeginDate", mStates.licenseBeginDate.get());
        if ("0".equals(mStates.licenseValidityType.get()))
            params.addProperty("licenseEndDate", mStates.licenseEndDate.get());
        params.addProperty("foundDate", mStates.foundDate.get());//成立时间

        if ("3".equals(mStates.entType.get())) {
            params.addProperty("regCapital", mStates.regCapital.get());
        }
        params.addProperty("entType", mStates.entType.get());//公司類型

        if ("0".equals(mStates.legalCertValidityType.get())) {
            params.addProperty("legalCertEndDate", mStates.legalCertEndDate.get());
        }

        params.addProperty("legalCertValidityType", mStates.legalCertValidityType.get());//法人证件类型

        params.addProperty("legalCertBeginDate", mStates.legalCertBeginDate.get());
        params.addProperty("regName", mStates.regName.get());
        params.addProperty("shortName", mStates.shortName.get());
        params.addProperty("spid", mStates.spid.get());
        params.addProperty("regDistrictId", mStates.regDistrictId.get());
        params.addProperty("regDetail", mStates.regDetail.get());
        params.addProperty("legalName", mStates.legalName.get());
        params.addProperty("legalCertNo", mStates.legalCertNo.get());
        params.addProperty("legalAddr", mStates.legalAddr.get());
        params.addProperty("loginName", mStates.contactMobileNo.get());
        params.addProperty("contactMobileNo", mStates.contactMobileNo.get());
        params.addProperty("contactEmail", mStates.contactEmail.get());

        if ("0".equals(mStates.cardType.get())) {//0：对公账户 1：对私法人账户 2：对私非法人账户
            JsonArray regAcctPic = new JsonArray();
            regAcctPic.add(mStates.regAcctPic.get());
            params.add("regAcctPic", regAcctPic);//开户许可证
            params.addProperty("openLicenceNo", mStates.openLicenceNo.get());
        } else {
            JsonArray licensePicUrls = new JsonArray();
            licensePicUrls.add(mStates.settleCardFrontPic.get());
            params.add("licensePicUrls", licensePicUrls);//银行卡照片
        }

        JsonObject cardInfo = new JsonObject();
        cardInfo.addProperty("cardName", mStates.cardName.get());
        cardInfo.addProperty("bankAreaId", mStates.bankAreaId.get());
        cardInfo.addProperty("bankName", mStates.bankName.get());
        cardInfo.addProperty("cardType", mStates.cardType.get());
        cardInfo.addProperty("cardNo", mStates.cardNo.get());
        cardInfo.addProperty("subBankName", mStates.subBankName.get());
        params.add("cardInfo", cardInfo);
        params.addProperty("typeId", mStates.typeId.get());
        params.addProperty("serviceCenterId", mStates.serviceCenterId.get());
        params.addProperty("checked", mStates.checked.get());
        params.addProperty("zhhtMerchantsType", mStates.zhhtMerchantsType.get());

        params.addProperty("licenseValidityType", mStates.licenseValidityType.get());
//        params.addProperty("legalCertType", mStates.legalCertType.get());//法人证件类型，参考《自然人证件类型》；当useHeadInfoFlag=Y时不填；开通全域资金管理管理只支持法人证件类型是身份证


        params.addProperty("mcc", mStates.mccCode.get());

        JsonArray licensePic = new JsonArray();
        licensePic.add(mStates.licensePic.get());
        params.add("licensePic", licensePic);

        JsonArray storeHeaderPic = new JsonArray();
        storeHeaderPic.add(mStates.storeHeaderPic.get());
        params.add("storeHeaderPic", storeHeaderPic);

        JsonArray storeIndoorPic = new JsonArray();
        storeIndoorPic.add(mStates.storeIndoorPic.get());
        params.add("storeIndoorPic", storeIndoorPic);

        JsonArray storeCashierDeskPic = new JsonArray();
        storeCashierDeskPic.add(mStates.storeCashierDeskPic.get());
        params.add("storeCashierDeskPic", storeCashierDeskPic);

        JsonArray legalCertFrontPic = new JsonArray();
        legalCertFrontPic.add(mStates.legalCertFrontPic.get());
        params.add("legalCertFrontPic", legalCertFrontPic);//身份证人面像

        JsonArray legalCertBackPic = new JsonArray();
        legalCertBackPic.add(mStates.legalCertBackPic.get());
        params.add("legalCertBackPic", legalCertBackPic);//身份证国徽


        return params;
    }

    public class ClickProxy {

        public void openRecord() {
            startActivity(new Intent().setClass(BusinessNewSettledActivity.this, BusinessSettleRecordActivity.class));
        }

        public void openWebview() {
            startActivity(new Intent()
                    .putExtra("id", "1")
                    .putExtra("title", "品质与服务承诺书")
                    .setClass(BusinessNewSettledActivity.this, WebViewApiActivity.class));
        }

        public void submit() {

            if (StringUtil.isEmpty(mStates.licensePic.get())) {
                mBinding.mprvBusinessLicense.photoAdapter.getPhotoPaths().clear();
                ToastUtils.showShortToast("营业执照不能为空");
                return;
            }
            if (StringUtil.isEmpty(mStates.mccCode.get())) {
                ToastUtils.showShortToast("所属行业不能为空");
                return;
            }
            getController().displayLoading();
            Log.e("params", getHttpParams().toString());
            mAccountRequester.addTenant(getHttpParams());
        }

        public void deliveryType() {

            OptionsPickerView<LibraryInfo> mOptionsPickerView = new OptionsPickerView.Builder(BusinessNewSettledActivity.this
                    , new OptionsPickerView.OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {

                    mStates.typeName.set(mStates.shopTypes.get().get(options1).getPickerViewText());
                    mStates.typeId.set(mStates.shopTypes.get().get(options1).getTypeId());
                }
            }).setTitleText("请选择分类").build();
            mOptionsPickerView.setPicker(mStates.shopTypes.get());
            mOptionsPickerView.show();
        }

        public void openMCC() {
            startActivityForResult(new Intent().setClass(BusinessNewSettledActivity.this, BusinessMccActivity.class), 1006);
        }

        /**
         * 时间选择器
         *
         * @param type 0营业执照开始时间 1结束时间 2成立时间  3法人开始时间 4结束时间
         */
        public void times(int type) {

            SimpleDateFormat ymd = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());

            boolean[] timeType = new boolean[]{true, true, true, false, false, false};//显示类型 默认全部显示

            new TimePickerView.Builder(BusinessNewSettledActivity.this, new TimePickerView.OnTimeSelectListener() {
                @Override
                public void onTimeSelect(Date date, View v) {
                    String time = ymd.format(date);
                    if (type == 0) {
                        mStates.licenseBeginDate.set(time);
                    } else if (type == 1) {
                        mStates.licenseEndDate.set(time);
                    } else if (type == 2) {
                        mStates.foundDate.set(time);
                    } else if (type == 3) {
                        mStates.legalCertBeginDate.set(time);
                    } else if (type == 4) {
                        mStates.legalCertEndDate.set(time);
                    }
                }
            }).isCyclic(false)
                    .setRangDate(null, null)
                    .setType(timeType)
                    .setDate(Calendar.getInstance()).build().show();
        }

        public void serviceType() {

            OptionsPickerView<BusinessBean> mOptionsPickerView = new OptionsPickerView.Builder(BusinessNewSettledActivity.this
                    , new OptionsPickerView.OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {

                    mStates.serviceCenterName.set(mStates.serviceTypes.get().get(options1).getPickerViewText());
                    mStates.serviceCenterId.set(mStates.serviceTypes.get().get(options1).getTypeId());
                }
            }).setTitleText("请选择分类").build();
            mOptionsPickerView.setPicker(mStates.serviceTypes.get());
            mOptionsPickerView.show();
        }
    }
}
